﻿@model  Authentication.Model.ViewModel.Customer.IncentiveAdhocViewModel
<ul class="breadcrumb">
    <li>
        <i class="icon-home"></i>
        <a href="/">Custommer</a>
        <i class="icon-angle-right"></i>
    </li>
    <li>
        <i class="icon-lock"></i>
        <a href="#">IncentiveAdhoc</a>
    </li>
</ul>
<!--/span-->
<div class="row-fluid">
    <div class="box span12 orange">
        <div class="box-header" data-original-title>
            <h2><i class="halflings-icon search white"></i><span class="break"></span>Search infomation</h2>
        </div>
        <div class="box-content">
            <div class="row-fluid">
                <div class="span3">
                    <div class="desc">
                        <div class="title">Scheme Name</div>
                        <div>
                            @Html.TextBoxFor(m => m.SchemeNameSearch, new { @class = "span12" })
                        </div>
                    </div>
                </div>
                <div class="span3">
                    <div class="desc">
                        <div class="title">Period</div>
                        <div>
                            @Html.TextBoxFor(m => m.StartDateSearch, new { @class = "span6 datepicker datemask" })
                            @Html.TextBoxFor(m => m.EndDateSearch, new { @class = "span6 datepicker datemask" })
                        </div>
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <button id="btnSearch" type="submit" class="btn btn-success btn-responsive"><i class="icon-search"></i>&nbsp;Search</button>
            </div>
        </div>
    </div>
</div>
<!--/row-->
<div class="row-fluid">
    <div class="box span12">
        <div class="box-header" data-original-title>
            <h2><i class="halflings-icon lock"></i><span class="break"></span>Items</h2>
            <div class="box-icon">
                <a href="#" class="btn-minimize"><i class="halflings-icon chevron-up"></i></a>
            </div>
        </div>
        <div class="box-content">
            <table class="table table-striped bootstrap-datatable datatable" id="dataTables-1">
                <thead>
                    <tr>
                        <th class="text-left all">Scheme Code</th>
                        <th class="text-left all">Scheme Name</th>
                        <th class="text-left all">Purpose</th>
                        <th class="text-left all">Start Date</th>
                        <th class="text-left all">End Date</th>
                        <th class="text-left all">Close Date</th>
                        <th class="text-left all">Mdi</th>
                        <th class="text-left all">Purpose Type</th>
                        <th class="text-left all">Bill to Code</th>
                        <th class="text-left all">Area</th>
                        <th class="text-left all" style="width: 60px;">Action</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            <div class="form-actions">
                @if (true)
                {
                    <button id="btnNewIncentiveAdhoc" class="btn btn-success btn-responsive">Add New IncentiveAdhoc</button>
                }
            </div>
        </div>
    </div>
    <!--/span-->
</div>
<!--/row-->
@*Check permission*@
@if (true)
{
    <div id="incentiveAdhocEditor" class="modal fade box brown">
        <div class="box-header">
            <h2><i class="halflings-icon white list"></i><span class="break"></span>IncentiveAdhoc Confirmation</h2>
            <div class="box-icon">
                <a data-dismiss="modal" class="close"><i class="halflings-icon white remove"></i></a>
            </div>
        </div>
        <div class="box-content">
            @using (Html.BeginForm("IncentiveAdhoc", "Customer", FormMethod.Post, new { @class = "form-horizontal", name = "Update", id = "Update" }))
            {
                <div class="validation-summary alert alert-error">
                    <a class="close" data-dismiss="alert">×</a>
                    <h5 class="alert-heading">IncentiveAdhoc validation</h5>
                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary()
                </div>
                <fieldset>
                    <div class="control-group">
                        @Html.LabelFor(m => m.SchemeCode, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(m => m.SchemeCode, new { @class = "span10" })
                            @Html.Hidden("btnClick")
                        </div>
                    </div>
                    <div class="control-group">
                        @Html.LabelFor(m => m.SchemeName, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(m => m.SchemeName, new { @class = "span10" })
                        </div>
                    </div>
                    <div class="control-group">
                        @Html.LabelFor(m => m.Purpose, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(m => m.Purpose, new { @class = "span10" })
                        </div>
                    </div>
                    <div class="control-group">
                        @Html.LabelFor(m => m.StartDate, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(m => m.StartDate, new { @class = "span10 datepicker datemask" })
                        </div>
                    </div>
                    <div class="control-group">
                        @Html.LabelFor(m => m.EndDate, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(m => m.EndDate, new { @class = "span10 datepicker datemask" })
                        </div>
                    </div>
                    <div class="control-group">
                        @Html.LabelFor(m => m.CloseDate, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(m => m.CloseDate, new { @class = "span10 datepicker datemask" })
                        </div>
                    </div>
                    <div class="control-group">
                        @Html.LabelFor(m => m.Mdi, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(m => m.Mdi, new { @class = "span10" })
                        </div>
                    </div>
                    <div class="control-group">
                        @Html.LabelFor(m => m.PurposeType, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(m => m.PurposeType, new { @class = "span10" })
                        </div>
                    </div>
                    <div class="control-group">
                        @Html.LabelFor(m => m.BilltoCode, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(m => m.BilltoCode, new { @class = "span10 billto-val" })
                        </div>
                    </div>
                    <div class="control-group">
                        @Html.LabelFor(m => m.RegionIdentifier, new { @class = "control-label" })
                        <div class="controls">
                            @Html.DropDownListFor(m => m.RegionIdentifier, new SelectList(Authentication.Web.Controller.Helper.Regions, "RegionIdentifier", "RegionName"), new { @class = "span4 region-val" })
                        </div>
                    </div>
                    <div class="form-actions modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <input type="submit" name="btnUpdate" id="btnUpdate" class="btn btn-primary" value="Save changes" />
                    </div>
                </fieldset>
            }
        </div>
    </div>
}

@section scripts
{
    <script>
        $(document).ready(function () {
            RefreshTable("#dataTables-1");
        });

        function buildAjaxSourcUrl() {
            var orgURL = '?schemename=' + $('#SchemeNameSearch').val() + '&startdate=' + $('#StartDateSearch').val() + '&enddate=' + $('#EndDateSearch').val();

            if (orgURL.length > 1) {
                orgURL = '@Url.Action("SearchIncentiveAdhoc")' + orgURL;
            } else {
                orgURL = '@Url.Action("SearchIncentiveAdhoc")';
            }
            return orgURL;
        }

        function RefreshTable(tableId) {
            var urlData = buildAjaxSourcUrl();
            table = $(tableId).dataTable();
            table._fnClearTable(table.oSettings);
            table.fnDestroy();
            table.fnDraw(true);
            var table2 = $(tableId).dataTable({
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                oLanguage: {
                    sProcessing: "<img src='http://www.arabianbusiness.com/skins/ab.main/gfx/loading_spinner.gif'/>"
                },
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 30,
                "sAjaxSource": urlData,
                "fnServerParams": function (aoData) {
                    aoData.push({ "name": "myval", "value": $('#myselect :selected').val() });
                },
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "sPaginationType": "bootstrap",//"full_numbers",
                "aoColumns": [
                            { "sName": "SchemeCode", "bSortable": false },//0
                            { "sName": "SchemeName", "bSortable": false },//0
                            { "sName": "Purpose", "bSortable": false },//1
                            { "sName": "StartDate", "bSortable": false },//2
                            { "sName": "EndDate", "bSortable": false },//3
                            { "sName": "CloseDate", "bSortable": false },//4
                            { "sName": "Mdi", "bSortable": false },//5
                            { "sName": "PurposeType", "bSortable": false },//6
                            { "sName": "BilltoCode", "bSortable": false },//7
                            { "sName": "RegionIdentifier", "bSortable": false },//8
                            ],
                "aoColumnDefs": [{
                    "aTargets": [10],
                    "mData": null,
                    "mRender": function (data, type, full) {
                        return '<button class=\"btn btn-small btn-success\" onclick=\"showIncentiveAdhocEditor(\'' + full[0] + '\',\'' + full[1] + '\',\'' + full[2] + '\',\'' + full[3] + '\',\'' + full[4] + '\',\'' + full[5] + '\',\'' + full[6] + '\',\'' + full[7] + '\',\'' + full[8] + '\',\'' + full[9] + '\');\"><i class=\"halflings-icon white edit\"></i></button> <button class=\"btn btn-small btn-danger\" onclick=\"deleteIncentiveAdhoc(\'' + full[0] + '\',\'' + full[1] + '\');\"><i class=\"halflings-icon white trash\"></i></button>';
                    }
                }]
            });
        }

    </script>
    @*Check permission*@
    @if (true)
    {
        <script type="text/javascript">
            function showIncentiveAdhocEditor(schemeCode, schemeName, purpose, startDate, endDate, closeDate, mdi, purposeType, billtoCode, regionIdentifier) {
                $('#btnNewIncentiveAdhoc').val(null);
                $('#SchemeCode').val(schemeCode);
                $('#SchemeName').val(schemeName);
                $('#Purpose').val(purpose);
                $('#StartDate').val(startDate);
                $('#EndDate').val(endDate);
                $('#CloseDate').val(closeDate);
                $('#Mdi').val(mdi);
                $('#PurposeType').val(purposeType);
                $('#BilltoCode').val(billtoCode);
                $('#RegionIdentifier').val(regionIdentifier);
                $("#incentiveAdhocEditor").modal('show');
            }

            function deleteIncentiveAdhoc(key, id) {
                if (confirm('Your data will be lost, are you really?')) {
                    $.post('@Authentication.Configuration.SystemConfiguration.DeleteIncentiveAdhhocAction/', { code: key }, function (data) {
                        if (data.IsSuccess) reload();
                    });
                }
            }
            $("#btnNewIncentiveAdhoc").click(function () {
                showIncentiveAdhocEditor(null, null, null, null, null, null, null, null, null, null, null, null);
                $('#btnClick').val('btnNewIncentiveAdhoc');
            });

            $("#btnSearch").click(function () {
                RefreshTable("#dataTables-1");
            });
        </script>
    }
}  